/* 
 防抖
 
 页面内使用
 import { useDebounce } from '@/hooks/useDebounce.js'
 const { debounce } = useDebounce()
 debounce(() => {
	// 事件逻辑
	
 },1000)
 */

const useDebounce = () => {
	const timer = ref(null)

	const debounce = (fn, delay = 100) => {
		if (timer.value) {
			clearTimeout(timer.value)
			timer.value = setTimeout(() => {
				fn()
			}, delay)
		} else {
			timer.value = setTimeout(() => {
				fn()
			}, delay)
		}
	}

	return { debounce }
}

export { useDebounce }
